﻿<template>
	<el-dialog :title="!dataForm.id ? '新建' : '编辑'" :close-on-click-modal="false" :visible.sync="visible"
		class="SHZY-dialog SHZY-dialog_center" lock-scroll width="600px" append-to-body>
		<el-row :gutter="15" class="">
			<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :rules="rules">
				
				<el-col :span="24">
					<el-form-item label="文件信息" prop="fileInfo">
						<SHZY-UploadFz v-model='dataForm.fileInfo' required :fileSize='20' sizeUnit='MB' :limit='1'
							buttonText='点击上传'>
						</SHZY-UploadFz>
					</el-form-item>
				</el-col>
			
				<el-col :span="24">
					<el-form-item label="备注" prop="remark">
						<el-input v-model='dataForm.remark' placeholder='请输入' maxlength="20" clearable required show-word-limit type="textarea"
							:style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
import customerAPI from '@/api/q1/business/customer';
export default {
	components: {},
	props: [],
	data() {
		
		return {
			btnLoading: false,
			loading: false,
			visible: false,
			dataForm: {
				id:'',
				customerId:'',
				fileInfo: [],
				remark:'',
				type:''
			
			},
			rules: {
				
				fileInfo: [
					{
						required: true,
						message: '请输入模板信息',
						trigger: '"click"'
					},
				],
			},
			typeList: [],
		}
	},
	computed: {},
	watch: {},
	created() {
	
	},
	mounted() {
	},
	methods: {
	
		goBack() {
			this.$emit('refresh')
		},
		init(id,fileid,type) {
			this.dataForm.id = fileid;
			this.dataForm.customerId = id || 0;
			this.dataForm.type = type;
			this.visible = true;
			this.$nextTick(() => {
				this.$refs['elForm'].resetFields();
				if (this.dataForm.id) {
					customerAPI.getqmsbusicustomerfile(this.dataForm.id).then(res => {
						console.log(res.data)
						this.dataForm = res.data;
						if (!this.dataForm.fileInfo) this.dataForm.fileInfo = [];
					})
				}
			});
		},
		dataFormSubmit() {
			this.$refs['elForm'].validate((valid) => {
				if (valid) {
					this.btnLoading = true;
					const formMethod = !this.dataForm.id ? customerAPI.qmsbusicustomerfile : customerAPI.updateqmsbusicustomerfile;
					formMethod(this.dataForm).then((res) => {
						this.btnLoading = false;
						this.$message({
							message: res.msg,
							type: 'success',
							duration: 1000,
							onClose: () => {
								this.visible = false,
								this.$emit('confirm',res.data)
							}
						})
					}).catch((res) => {
						this.btnLoading = false;
					})
				}
			})
		},
	}
}
</script>
